/********************************************
 * Joe Helgeson
 * CS362 Assignment 3
 * Unit tests for card-specific functions
 *
 * cardtest4.c - tests outpost
 * (gives +1 turn, but with only 3-card draw)
 *******************************************/

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

//enabling debugging messages to appear
//#ifdef DEBUG
//#undef DEBUG
//#endif
//#define DEBUG 1

void testIt(struct gameState* tState);

///////////////////////////////////////
int main(int argc, char const** argv) {
	struct gameState* tState = malloc(sizeof(struct gameState));
	testIt(tState);
	free(tState);
	return 0;
}

///////////////////////////////////////
void testIt(struct gameState* tState) {

/* personal notes (ignore): 
 int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, struct gameState *state)
 int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
*/

	//general initial game setup
	srand(time(NULL));
	int numPlayers = 2;
	int kingdomCards[10];
	int i;
	for (i=0; i<10; i++){
		kingdomCards[i] = i+15;		//offset by 15 to be sure outpost is covered in kingdom cards in play
	}
	int randomSeed = rand() % 100; //arbitrary number for various functions (usually set by user on cmd line with playdom)
	
	//initialize game (but doesn't create a discard pile)
	int res1 = initializeGame(numPlayers, kingdomCards, randomSeed, tState);
	assert(res1 == 0);

	//specific setup for card under test
	int player = 0;
	int handPos = 0;
	int card = outpost;
	int choice1 = 0; //irrelevant for this card
	int choice2 = 0; //irrelevant for this card
	int choice3 = 0; //irrelevant for this card
	int bonusval = 0; //irrelevant for this card
	int* bonus = &bonusval; //irrelevant for this card

	int t; //test number
	for (t=0; t<50; t++) {
		//randomly set hand size and save a backup
		tState->handCount[player] = rand() % 10 + 1; //need at least 1 card to play
		int origHandSize = tState->handCount[player];  //backup hand count to compare against
		printf("Testing card %d with a hand of %d cards, ", card, origHandSize);

		//init outpostPlayed variable
		int outpostPlayedOrig = rand() % 5; //set how many outposts have been played
		tState->outpostPlayed = outpostPlayedOrig;

		//test card #23 (outpost)
		int res2 = cardEffect(card, choice1, choice2, choice3, tState, handPos, bonus);
		assert(res2 == 0);

		//various post-play tests
		//check for 1 less card in hand
		if (tState->handCount[player] != (origHandSize - 1)) {
			printf("Test failed, hand size has not been decremented by 1\n");
			printf("Player handCount = %d, origHandSize = %d\n", tState->handCount[player], origHandSize);
			return;
		} 
		else {
			printf("Test passed, hand size decreased by 1\n");
		}

		//check for outpostPlayed to have been incremented by 1
		if (tState->outpostPlayed != outpostPlayedOrig + 1) {
			printf("Test failed, outpostPlayed variable not incremented by 1\n");
			return;
		}
		else {
			printf("Test passed, outpostPlayed incremented\n");
		}
	}
	printf("Outpost unit test passed.\n");
	return;
}

